/* ---------------------------------------------------------------------------------
 * time-format.c
 * Copyright (C) 2010 Muhammad Fauzilkamil Zainuddin <jerungkun@gmail.com>
 * http://coderstalk.blogspot.com
 * 
 * Description:
 *  Example code to print formatted timestamp in C.
 * ---------------------------------------------------------------------------------
 */
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
	time_t thetime;
	struct tm *timestruct;
	char formatted_time[32];
	
	printf(":: Printing time format in C - by ApOgEE ::\n");
	printf("-------------------------------------------\n");
	
	/* get current time */
	thetime = time(NULL);

	/* format the time to ddd mmm dd yyyy  hh:mm:ss ampm*/
	timestruct = localtime(&thetime);
	strftime(formatted_time,sizeof(formatted_time),"%a %b %d %Y  %I:%M:%S %p",timestruct);

	/* print the timestamp */	
	printf("The formatted timestamp is: %s\n",formatted_time);
	
	return 0;
}
